<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>

<script type="text/javascript" src="<%=request.getContextPath()%>/resource/lib/plugins/ajaxfileupload.js"></script>
<script type="text/javascript">
	$(function() {
		initUploadGrid();//初始化结构化上传
	});
	
	var mateGrid = null;
	//结构化上传
	function initUploadGrid(){
		
		var ctrlKey='3';// 1上传删除 2操作验证 3查看
		<c:if test="${detailFlag!=true }">
			ctrlKey='1';
      	</c:if>
      	<c:if test="${checkDy==1}">
			ctrlKey='2';
	  	</c:if>
		<c:if test="${1 == checkSpPass || 1 == checkDyPass}">
			ctrlKey='2';
		</c:if>
		var isQZ=0;
		if('${isQZ}'=='1'){
			isQZ=1;
		}
      	var from = $("#from").val();//mtg抵押页面 、上牌页面
		
		
		mateGrid = $("#mateGrid1").ligerGrid({
            url: '<%=request.getContextPath()%>/project/prjprdlicinfo/initMateList.do?prjPrdDtlId=${dtlId}&from='+from,
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h = rowdata.datNm;
                        if(rowdata.isMust == 1){
                            h += '(<span style="color:red;">*</span>)';
                        }
                        return h;
                    }
                },
                {display: '上传文件名称', name: 'fileNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            var h;
                            h='<a href="javascript:uploadFileByUrl(';
                            h+="'"+rowdata.filePath+"'";
                            h+=",'"+rowdata.fileNm+"'";
                            h+=')">'+rowdata.fileNm+'</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
                {display: '状态', name: 'audStsCdNm', width: 100, align: 'left', enabledSort: false},
                {display: '操作', name: 'upLoadNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='';
                        if(rowdata.fileId){
                        	//如果是权证
                        	if(isQZ==1 && ctrlKey!=3){
                            	if(!(rowdata.cfgCd =='PRJ015' && rowdata.cfgDtlCd=='242')){
                            		h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',1)"></span>';
                            	}
                            	//if(rowdata.audStsCd!=1) {
                                    h+='<span class="sq-button sq-button-round fileupload-button" onclick="delFile(' + rowdata.fileId + ',\''+rowdata.orgCd+'\',1);">删除</span>';
                                //}
                            	if(rowdata.filePath) {
                                    h += '<a class="sq-button-hasicon  button_tongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',1,1);"><i class="sqBtnIco_15"></i>验证通过</a>';
                                    h += '<a class="sq-button-hasicon  button_butongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',2,1);"><i class="sqBtnIco_14"></i>验证不通过</a>';
                                }
                            }
                        	//1、排除历史数据：PRJ006上牌资料 PRJ007抵押资料
                        	else if(( ctrlKey==1 || ctrlKey==4) && rowdata.cfgCd !='PRJ006' && rowdata.cfgCd !='PRJ007'){
                            	// 2、登记证-抵押我司页只能上传一页
                            	if(!(rowdata.cfgCd =='PRJ015' && rowdata.cfgDtlCd=='242')){
                            		h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',1)"></span>';
                            	}
                            	//if(rowdata.audStsCd!=1) {
                                    h+='<span class="sq-button sq-button-round fileupload-button" onclick="delFile(' + rowdata.fileId + ',\''+rowdata.orgCd+'\',1);">删除</span>';
                                //}
                            	
                            }else if( ctrlKey==2){
                                {
                                	if(rowdata.filePath) {
                                        h += '<a class="sq-button-hasicon  button_tongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',1,1);"><i class="sqBtnIco_15"></i>验证通过</a>';
                                        h += '<a class="sq-button-hasicon  button_butongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',2,1);"><i class="sqBtnIco_14"></i>验证不通过</a>';
                                    }
                                }

                            }
                        	
                        }else{
                            if((isQZ==1 ||ctrlKey==1 || ctrlKey==4) && rowdata.cfgCd !='PRJ006'&& rowdata.cfgCd !='PRJ007'){
                                h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',1)"></span>';
                            }
                        }
                        return h;
                    }
                },
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,

            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: function (s) {
                $('#mateGrid1').rowspan('datNm');//合并单元格
                //显示验证的抵押结果
                if (typeof showCheckMgt != 'undefined' && showCheckMgt instanceof Function) {
                	showCheckMgt();
                }
            }
        });
	}
	
	
	 //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
	
    function onChangefile_multi(e,cfgCd,cfgDtlCd,orgCd,typ) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath="capital/capPayInfo";
        

        $.ajaxFileUpload({
            url: '<%=request.getContextPath()%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath},
            success: function (msg) {
                if (msg.success == 1) {
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: {
                                'fileParams': JSON.stringify(msg.data),
                                'prjPrdDtlId': '${dtlId}',
                                'prjId': $("#prjId").val(),
                                'cfgCd': cfgCd,
                                'cfgDtlCd': cfgDtlCd,
                                'id': $("#payId").val(),
                                'orgCd': orgCd
                            },
                            url: '<%=request.getContextPath()%>/capital/capPayInfo/uploadMate.do',
                            success: function (msg) {
                                wait_dialog.close();
                                if (msg.success == 1) {
                                       mateGrid.reload();
                                } else {
                                    $.ligerDialog.SQalert({content: "资料上传失败", SQ_type: "error"});
                                }
                            }
                        });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
    
    //删除文件
    function delFile(_fileId,_orgCd,typ){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'id':'','prjPrdDtlId':'${dtlId}','fileId':_fileId,'orgCd':_orgCd},
            url: '<%=request.getContextPath()%>/capital/capPayInfo/removeMate.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    mateGrid.reload();
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
    
    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            //SQ.imgPreview(_url);
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=request.getContextPath()%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else if(SQ.regs.img.test(_url)){
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }
  //修改资料的验证状态
    function modifyAudStsCd(_fileId,_audStsCd,flag){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileId':_fileId,'audStsCd':_audStsCd},
            url: '<%=path%>/project/prjFileInfo/modifyFileAudStsCd.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    //$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    /* if(prjPrdDtlFileInfoGrid){
                    	prjPrdDtlFileInfoGrid.reload();
                    } */
                   // event.stopPropagation();
                	mateGrid.reload();
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
</script>

<!-- 结构化上传 -->
<div class="sqPanel">
	<div class="sqPanel_head inL">
		<span>上传附件信息</span>
		<!-- <span class="sq-button sq-button-round" onclick="downloadFileByUrl('mateGrid');">打包下载</span> -->
	</div>
	<div class="sqPanel_body">
		<div id="mateGrid1" class="sq-grid"></div>
	</div>
</div>

<!-- 结构化上传 结束 -->